package me.youline.dataServer.entity;

import java.io.Serializable;
import java.util.Date;

import org.apache.commons.lang3.StringUtils;

/**
 * 用户TOKEN数据
 * @author linhan
 *
 */
public class UserToken implements Serializable {

	private static final long serialVersionUID = 8395235881464413865L;

	/**
	 * Token字符串
	 */
	private String token;

	/**
	 * 用户名
	 */
	private String userName;

	/**
	 * 用户ID
	 */
	private Long userId;

	/**
	 * 过期时间
	 */
	private Long expiredAt;
	
	/**
	 * 登陆设备号
	 */
	private String deviceToken;

	/**
	 * token创建时间
	 */
	private Date createTime;

	public String getToken() {
		return token;
	}

	public void setToken(String token) {
		this.token = token;
	}

	public Long getExpiredAt() {
		return expiredAt;
	}

	public void setExpiredAt(long expiredAt) {
		this.expiredAt = expiredAt;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public boolean isExpired(Date date) {
		if (date == null) {
			date = new Date();
		}
		if (StringUtils.isBlank(this.getUserId().toString())
				|| StringUtils.isBlank(this.getUserName())
				|| StringUtils.isBlank(this.getToken())) {
			return false;
		}
		if (this.getExpiredAt() != null) {
			return this.getExpiredAt() < date.getTime();
		} else {
			return true;
		}
	}

	public boolean isExpired() {
		return this.isExpired(null);
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public Long getUserId() {
		return Long.valueOf(userId);
	}

	public void setUserId(Long userId) {
		this.userId = userId;
	}

	public String getDeviceToken() {
		return deviceToken;
	}

	public void setDeviceToken(String deviceToken) {
		this.deviceToken = deviceToken;
	}
	

}
